package com.ruitu.health_2.mvp.presenter;

import com.ruitu.arad.base.BasePresenter;
import com.ruitu.arad.util.ToastUtils;
import com.ruitu.health_2.mvp.model.ArticleModel;
import com.ruitu.health_2.ui.common.ArticleListActivity;
import com.ruitu.router_module.bean.BaseResult2;
import com.ruitu.router_module.bean.PageModel2;
import com.ruitu.router_module.bean.article.Article;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

public class ArticlePresenter {

    public static class ArticleListP extends BasePresenter<ArticleListActivity, ArticleModel.ArticleListM> {

        public Disposable reqArticleListByTitle(int size, int num, String title) {
            return m.reqArticleListByTitle(size, num, title).subscribe(new Consumer<BaseResult2<PageModel2<Article>>>() {
                @Override
                public void accept(BaseResult2<PageModel2<Article>> baseResult) throws Exception {
                    v.hideProgress();
                    if (baseResult.isSuccess()) {
                        v.onReqComplete(1, true, baseResult.getData());
                    } else {
                        ToastUtils.showShortSafe(baseResult.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    throwable.printStackTrace();
                    v.hideProgress();
                }
            });
        }

        public Disposable reqArticleListByColumn(String posId, int size, int num) {
            return m.reqArticleListByColumn(posId, size, num).subscribe(new Consumer<BaseResult2<PageModel2<Article>>>() {
                @Override
                public void accept(BaseResult2<PageModel2<Article>> baseResult) throws Exception {
                    v.hideProgress();
                    if (baseResult.isSuccess()) {
                        v.onReqComplete(1, true, baseResult.getData());
                    } else {
                        ToastUtils.showShortSafe(baseResult.getMessage());
                    }
                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {
                    throwable.printStackTrace();
                    v.hideProgress();
                }
            });
        }
    }
}
